home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0192.ARJ / DISP.C < prev    next >
Text File  |  1991-09-04  |  6KB  |  273 lines

  1. /****************************************************************
  2.  *                                                              *
  3.  * DISP.C - menus, etc. for CopyBuilder 386                     *
  4.  * See makefile for compile directives                          *
  5.  * Al Williams -- August 1991                                   *
  6.  *                                                              *
  7.  ****************************************************************/
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <direct.h>
  13. #include <setjmp.h>
  14. #include <signal.h>
  15. #include "cb386.h"
  16. #include "display.h"
  17.  
  18.  
  19. /* display information screen */
  20. disp()
  21.   {
  22.   color=TEXTCOLOR;
  23.   cls();
  24.   color=SOCOLOR;
  25.   clreol();
  26.   writes(" Read  Write  Load  Save  Options  Dos  Exit");
  27.   goxy(73,0);
  28.   writes("F1=Help");
  29.   color=TEXTCOLOR;
  30.   goxy(33,1);
  31.   writes("386 CopyBuilder");
  32.   goxy(1,3);
  33.   writes("Current status:\n\n\r");
  34.   printfc(" Title: %s\n\n\r",bufinfo.title);
  35.   printfc(" Size: %-8d  Copies: %-6d  Source: %s\n\n\r",
  36.       bufinfo.size,bufinfo.copies,bufinfo.source);
  37.   printfc(" Checksums: Stored=%04X  Computed=%04X\n\n\r",
  38.       bufinfo.csum,bufinfo.ccsum);
  39.   writecc(0xc4,80);
  40.   curshide();
  41.   }
  42.  
  43. /* Jump buffer for break handling */
  44. jmp_buf onbreak;
  45. /* pointer to extra break function */
  46. void (*when_break)()=NULL;
  47.  
  48. /* primary break function */
  49. void breakfunc(int sig)
  50.   {
  51. /* recapture break key */
  52.   signal(SIGINT,breakfunc);
  53. /* do extra break function if present */
  54.   if (when_break) when_break();
  55. /* go back to top of menu loop */
  56.   longjmp(onbreak,1);
  57.   }
  58.  
  59. /* main menu */
  60. menu()
  61.   {
  62.   int c;
  63.   char tfmtcmd[129];
  64. /* catch ^C -- signal is OK since we redraw the whole
  65.    screen first thing. */
  66.   signal(SIGINT,breakfunc);
  67. /* return here when ^C pressed */
  68.   setjmp(onbreak);
  69. /* display screen */
  70.   disp();
  71. /* main loop */
  72.   while (1)
  73.     {
  74. /* get command */
  75.     curshide();
  76.     c=getch();
  77.     if (!c) c=-getch();
  78. /* process commands (ext. keys are negative) */
  79.     switch (c>0?(int)toupper(c):c)
  80.       {
  81.       char fn[66];
  82. /* For each command the letter and ALT-letter are OK */
  83. case -0x12:
  84. case 'E':
  85.       m_exit();
  86.       break;
  87.  
  88. case -0x20:
  89. case 'D':
  90.       m_dos();
  91.       disp();
  92.       break;
  93.  
  94. case -0x13:
  95. case 'R':
  96.       m_read();
  97.       disp();
  98.       break;
  99.  
  100. case -0x11:
  101. case 'W':
  102.       m_write();
  103.       disp();
  104.       break;
  105.  
  106. case -0x1f:
  107. case 'S':
  108.       m_save();
  109.       disp();
  110.       break;
  111.  
  112. case -0x26:
  113. case 'L':
  114.       m_load();
  115.       disp();
  116.       break;
  117.  
  118. case -0x18:
  119. case 'O':
  120.       goxy(0,23);
  121.       printfc("Current: %-64.64s",fmtcmd);
  122.       ask("Format command:",NULL,TEXTCOLOR,sizeof(tfmtcmd)-1,
  123.           tfmtcmd,"Enter the format command string. C386 appends"
  124.           " the drive letter.");
  125.       if (*tfmtcmd) strcpy(fmtcmd,tfmtcmd);
  126.       goxy(0,23);
  127.       clreol();
  128.       break;
  129.  
  130. case -0x23:
  131. case 'H':
  132. case -59:
  133.       help();
  134.       break;
  135.  
  136.  
  137. default:
  138. /* ring bell for unknown command */
  139.       writec('\a');
  140.       }
  141.     }
  142.   }
  143.  
  144.  
  145. /* exit */
  146. m_exit()
  147.   {
  148. /* confirm if buffer is full and hasn't been written */
  149.   if (dirtyquery())
  150.     {
  151.     vidmode();
  152.     cdrestore();
  153.     okreboot();
  154.     exit(0);
  155.     }
  156.   }
  157.  
  158. /* read a disk */
  159. m_read()
  160.   {
  161.   int disk;
  162.   if (!dirtyquery()) return;
  163.   disk=prompt("Source drive: ",NULL,TEXTCOLOR);
  164.   if (disk==-1) return;
  165.   if (prompt(
  166.     "\aInsert disk. Press <SPACE> to continue or <ESC> to exit.",
  167.     " \r",TEXTCOLOR)==-1) return;
  168. /* hook ^C handler to do load_break (in FILEIO.C) if ^C) */
  169.   slbreak=when_break;
  170.   when_break=load_break;
  171.   read_disk(disk);
  172.   when_break=slbreak;
  173.   slbreak=NULL;
  174.   }
  175.  
  176. /* write to disk */
  177. m_write()
  178.   {
  179.   int disk;
  180.   int copies=1;
  181.   char buf[4];
  182.   if (!diskbuf)
  183.     {
  184.     advise("No disk image in memory");
  185.     return;
  186.     }
  187.   disk=prompt("Destination drive: ",NULL,TEXTCOLOR);
  188.   if (disk==-1) return;
  189.   /* prompt for copies */
  190.   if (ask("Number of copies (default=1): "
  191.           ,"0123456789",TEXTCOLOR,3,buf,
  192.           " Enter the number of copies you want.")==-1)
  193.       return;
  194.   copies=atoi(buf);
  195.   if (!copies) copies=1;
  196.   while (copies--)
  197.     {
  198.     if (prompt(
  199.     "\a\aInsert disk. Press <SPACE> to continue or <ESC> to exit.",
  200.     " \r",TEXTCOLOR)==-1) return;
  201. /* hook ^C handler to save_break (in FILEIO.C) */
  202.     slbreak=when_break;
  203.     when_break=save_break;
  204.     if (write_disk(disk)) bufinfo.copies++;
  205.     when_break=slbreak;
  206.     slbreak=NULL;
  207.     disp();
  208.     }
  209.   }
  210.  
  211.  
  212. /* prompt user if buffer is "dirty" */
  213. dirtyquery()
  214.   {
  215.   int stat=1;
  216.   if (bufinfo.dirty)
  217.     {
  218.     stat=prompt("\aBuffer not saved. Discard (Y/N)","NY",ERRCOLOR);
  219.     if (stat==-1) stat=0;
  220.     }
  221.   return stat;
  222.   }
  223.  
  224. /* Run DOS -- some versions of Codebuilder won't set the
  225.    prompt correctly */
  226. m_dos()
  227.   {
  228. /* clear screen and reset color */
  229.   vidmode();
  230.   putenv("PROMPT=Enter \"Exit\" to return to 386 "
  231.          "CopyBuilder\r\n$p$g");
  232.   if (system("command")<0)
  233.     advise("Could not execute COMMAND.COM");
  234. /* reset screen mode just in case */
  235.   vidmode();
  236.   curshide();
  237.   }
  238.  
  239.  
  240. /* main menu help screen */
  241. help()
  242.   {
  243.   vidsave();
  244.   color=TEXTCOLOR;
  245.   cls();
  246.   color=SOCOLOR;
  247.   clreol();
  248.   writes(" Read  Write  Load  Save  Options  Dos  Exit");
  249.   goxy(73,0);
  250.   writes("F1=Help");
  251.   color=TEXTCOLOR;
  252.   goxy(0,1);
  253.   writes("                                   \n\r");
  254.   writes("  │      │     │     │       │      │    │\n\r");
  255.   writes("  │      │     │     │       │      │    └─ Exit CB386\n\r");
  256.   writes("  │      │     │     │       │      │\n\r");
  257.   writes("  │      │     │     │       │      └─ Shell to DOS\n\r");
  258.   writes("  │      │     │     │       │\n\r");
  259.   writes("  │      │     │     │       └─ Set options\n\r");
  260.   writes("  │      │     │     │\n\r");
  261.   writes("  │      │     │     └─ Save working image to a disk file\n\r");
  262.   writes("  │      │     │\n\r");
  263.   writes("  │      │     └─ Load working image from a disk file\n\r");
  264.   writes("  │      │\n\r");
  265.   writes("  │      └─ Write working image to a floppy\n\r");
  266.   writes("  │\n\r");
  267.   writes("  └─ Read working image from a floppy\n\n\n\r");
  268.   goxy(25,23);
  269.   writes("CopyBuilder 386 by Al Williams");
  270.   prompt("Press any key to continue","",SOCOLOR);
  271.   vidrestore();
  272.   }
  273.